<?php
class class_ABMTiposUsuarios
{
	private $_db; 
	function __construct(){
		$this->config();
	}
	
	function method_getLista($params, $error){
		$this->_db->setQuery("SELECT * FROM tipos_usuarios");
		$this->_db->alter();
		if (mysql_error()) { $error->SetError(JsonRpcError_Unknown, (__FILE__ . " - " . (__LINE__ - 2) . ": " . mysql_error())); return $error; }
		$result = array();
		$regs = $this->_db->loadResult();
		$row = array();
    	FOREACH ($regs as $reg){
			array_push($row, $reg->cod_tipo_usuario);
			array_push($row, $reg->tipo);
			array_push($result, $row);
			$row = array();
		}
		return $result;
    }
    
	function method_btnBorrar($params, $error){
        if (count($params) != 1){ $error->SetError(JsonRpcError_ParameterMismatch, "Expected 1 parameter; got " . count($params)); return $error; }
        $this->_db->setQuery("DELETE FROM tipos_usuarios WHERE cod_tipo_usuario = '" . $params[0] . "'");
        $this->_db->alter();
		if (mysql_error()) { $error->SetError(JsonRpcError_Unknown, (__FILE__ . " - " . (__LINE__ - 2) . ": " . mysql_error())); return $error; }
		return true;
    }
    
	function method_btnModificar($params, $error){
        if (count($params) != 1){ $error->SetError(JsonRpcError_ParameterMismatch, "Expected 1 parameter; got " . count($params)); return $error; }
		$this->_db->setQuery("SELECT * FROM tipos_usuarios WHERE cod_tipo_usuario = '" . $params[0] . "' LIMIT 1");
		$this->_db->alter();
		if (mysql_error()) { $error->SetError(JsonRpcError_Unknown, (__FILE__ . " - " . (__LINE__ - 2) . ": " . mysql_error())); return $error; }
		$reg = $this->_db->loadResult();
		return $reg[0];
    }
    
	function method_opAlta($params, $error) {
        if (count($params) != 1) { $error->SetError(JsonRpcError_ParameterMismatch, "Expected 1 parameter; got " . count($params)); return $error; }
        $this->_db->setQuery("INSERT INTO tipos_usuarios (cod_tipo_usuario, tipo) VALUES (NULL, '" . $params[0]->tipo . "')");
        $this->_db->alter();
		if (mysql_error()) { $error->SetError(JsonRpcError_Unknown, (__FILE__ . " - " . (__LINE__ - 2) . ": " . mysql_error())); return $error; }
		return true;
    }
    
	function method_opModificacion($params, $error){
		if (count($params) != 1) { $error->SetError(JsonRpcError_ParameterMismatch, "Expected 1 parameter; got " . count($params)); return $error; }
	    $this->_db->setQuery("UPDATE tipos_usuarios SET tipo = '" . $params[0]->tipo. "' WHERE cod_tipo_usuario = '" . $params[0]->cod_tipo_usuario . "' LIMIT 1");
        $this->_db->alter();
		if (mysql_error()) { $error->SetError(JsonRpcError_Unknown, (__FILE__ . " - " . (__LINE__ - 2) . ": " . mysql_error())); return $error; }
		return true;
    }
    
	private function config(){
		require_once("conexion.php");
		require_once("DataBase.php");
		$this->_db = new DataBase($SERVIDOR,$USUARIO,$PASSWORD,$BASE);
		mysql_query("SET NAMES utf8");
	}
}
?>